﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Gift.Model;
using Gift.DAL;

namespace WebSite.admin.system
{
    public partial class Bulletin : BaseAdmin
    {
        readonly DALBulletin theBulletin = new DALBulletin();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                base.ValidateLoginRule(Gift.Model.ENUM.ERule.DefaultBulletin);
                this.BindBulletin();
            }
        }
        void BindBulletin()
        {
            tbBulletin oBulletin;
            oBulletin = theBulletin.GetModel(base.AdminShopId);
            if (oBulletin != null)
            {
                this.txtBody.Text = oBulletin.Bulletin;
            }
        }


        protected void ibtnSave_Click(object sender, ImageClickEventArgs e)
        {
            tbBulletin oBulletin;
            oBulletin = theBulletin.GetModel(base.AdminShopId);
            if (oBulletin == null)
            {
                oBulletin = new tbBulletin();
                oBulletin.Bulletin = this.txtBody.Text.Trim();
                oBulletin.LinkUrl = this.txtLinkUrl.Text.Trim();
                theBulletin.Add(oBulletin);
            }
            else
            {
                oBulletin.Bulletin = this.txtBody.Text.Trim();
                oBulletin.LinkUrl = this.txtLinkUrl.Text.Trim();
                theBulletin.Update(oBulletin);
            }
            Response.Write("<script>alert('保存成功!')</script>");

        }
    }
}